/**
 * @Title: index.js
 * @Package mall-fe
 * @author Shinelon
 * @date 2017/9/4 16:31
 * @version V1.0
 */
'use strict';
require('./index.css');
var shiqla = require('util/shiqlamall');
var templateIndex = require('./template.string');
var navSide = {
    option: {
        name: '',
        navList: [
            {
                name: 'user-center',
                desc: '个人中心',
                href: './user-center.html'
            },
            {
                name: 'order-List',
                desc: '我的订单',
                href: './order-List.html'
            },
            {
                name: 'user-pass-update',
                desc: '修改密码',
                href: './user-pass-update.html'
            },
            {
                name: 'about',
                desc: '关于SMALL',
                href: './about.html'
            }
        ]
    },
    init: function (option) {
        //合并选项
        $.extend(this.option,option);
        this.renderNav();
        return this;
    },
    renderNav: function () {
        // 计算active 数据
       for (var i =0,iLength = this.option.navList.length;i < iLength;i++){
           if(this.option.navList[i].name === this.option.name){
               this.option.navList[i].isActive = true;
           }
       }
       //渲染list 数据
        var navHtml = shiqla.renderHtml(templateIndex,{
            navList:this.option.navList
        });

        // 把thml 放入容器
        $('.nav-side').html(navHtml);
    }
};

module.exports = navSide;
